package com.api.shopapi.mapper;

import com.api.shopapi.entity.ActivityItem;
import com.api.shopapi.entity.AskAnswerGroup;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface AskAnswerGroupMapper {

    @Insert("insert into ask_answer_group " +
            "(" +
            "AskAnswerGroupCode," +
            "AskAnswerNameCode," +
            "Name," +
            "Status," +
            "GovernmentCode," +
            "CommandCenterCode," +
            "Type," +
            "Sort" +
            ") " +
            "values " +
            "(" +
            "#{askAnswerGroup.AskAnswerGroupCode}," +
            "#{askAnswerGroup.AskAnswerNameCode}," +
            "#{askAnswerGroup.Name}," +
            "#{askAnswerGroup.Status}," +
            "#{askAnswerGroup.GovernmentCode}," +
            "#{askAnswerGroup.CommandCenterCode}," +
            "#{askAnswerGroup.Type}," +
            "#{askAnswerGroup.Sort}" +
            ")" )
    int insert(@Param("askAnswerGroup") AskAnswerGroup askAnswerGroup);


    @Delete("delete from ask_answer_group where askAnswerGroupCode=#{askAnswerGroupCode}")
    int delete(@Param("askAnswerGroupCode") String askAnswerGroupCode);


    @Update("update ask_answer_group set " +
            " Name=#{askAnswerGroup.Name}," +
            " AskAnswerNameCode=#{askAnswerGroup.AskAnswerNameCode}," +
            " Status=#{askAnswerGroup.Status}," +
            " Sort=#{askAnswerGroup.Sort}" +
            " where askAnswerGroupCode=#{askAnswerGroup.askAnswerGroupCode}")
    int update(@Param("askAnswerGroup") AskAnswerGroup askAnswerGroup);


    @Select("select * from ask_answer_group where askAnswerGroupCode=#{askAnswerGroupCode} limit 1")
    AskAnswerGroup getByAskAnswerGroupCode(@Param("askAnswerGroupCode") String askAnswerGroupCode);


    @Select("select * from ask_answer_group where askAnswerNameCode=#{askAnswerNameCode}" +
            " order by Sort desc")
    List<AskAnswerGroup> listByAskAnswerNameCode(@Param("askAnswerNameCode") String askAnswerNameCode);


    @Select("<script>" +
            "select * from ask_answer_group where commandCenterCode=#{commandCenterCode}" +
            "<if test =' askAnswerNameCode != \"\" '>" +
            " and askAnswerNameCode = #{askAnswerNameCode} " +
            "</if>" +
            " order by Sort desc" +
            "</script>")
    List<AskAnswerGroup> listByCommandCenterCodeAskAnswerNameCode(@Param("commandCenterCode") String commandCenterCode,
                                                            @Param("askAnswerNameCode") String askAnswerNameCode);


    @Select("<script>" +
            "select * from ask_answer_group" +
            " where governmentCode=#{governmentCode}" +
            " and type=#{type}" +
            "<if test =' askAnswerNameCode != \"\" '>" +
            " and askAnswerNameCode = #{askAnswerNameCode} " +
            "</if>" +
            " order by Sort desc" +
            "</script>")
    List<AskAnswerGroup> listByGovCodeTypeAskAnswerNameCode(@Param("governmentCode") String governmentCode,
                                                            @Param("type") String type,
                                                        @Param("askAnswerNameCode") String askAnswerNameCode);


}
